package cn.wolfcode.wolf2w.util;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.query.QueryObject;
import org.springframework.data.domain.*;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 数据库操作工具类
 */
public class DBHelper {

    public static <T>  Page<T> query(MongoTemplate template,Pageable pageable, Query query, Class<T> clz,  QueryObject qo) {
        long total = template.count(query, clz);
        if(total == 0){
            return Page.empty();  //空的分页对象
        }
        query.with(pageable);
        List<T> list = template.find(query, clz);
        return new PageImpl<>(list, pageable, total);
    }




}
